use axum::Json;
use serde_json::Value;
use sea_orm::EntityTrait;
use crate::query;

use super::del::{many, one};

// 删除单个
pub async fn by_id_del_file<E:EntityTrait>(entity:E, id:&str, file:Vec<&str>, mongo:bool) -> Result<Json<Value>, Json<Value>>{ 
    one(entity, "id", None, Some(id), Some(file), mongo).await
}
pub async fn by_id<E:EntityTrait>(entity:E, id:&str) -> Result<Json<Value>, Json<Value>>{ 
    by_id_del_file(entity, id, Vec::new(), false).await 
}

// 删除多个
pub async fn by_ids_del_file<E:EntityTrait>(entity:E, id:&str, file:Vec<&str>, mongo:bool) -> Result<Json<Value>, Json<Value>>{
    let ids = query::utils::str_to_vec_str(&id, "")?;
    if ids.len() == 1 {
        let id = &ids[0];
        by_id_del_file(entity, id, file, mongo).await
    }else{
        many(entity, "id", None, Some(ids), Some(file), mongo).await
    }
}
pub async fn by_ids<E:EntityTrait>(entity:E, id:&str) -> Result<Json<Value>, Json<Value>>{by_ids_del_file(entity, id, Vec::new(), false).await}